package com.qys.livesMall.security.interceptor;

import com.qys.livesMall.security.interceptor.config.ExcludePathConfig;
import com.qys.livesMall.security.interceptor.core.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    @Configuration
public class MyWebAppConfigurer implements WebMvcConfigurer {
    	//tag 为true 则为开启状态，为false 则为关闭状态
    	private boolean tag=true;

		/**
		 * 注入bean
		 * @return
		 */
		@Autowired
		private LoginInterceptor loginInterceptor;

		@Autowired
		private RequestInterceptor requestInterceptor;

		@Autowired
		private SecurityInterceptor securityInterceptor;

		@Autowired
		private WordsInterceptor wordsInterceptor;

		@Autowired
		private ThreadInterceptor threadInterceptor;

//		@Autowired
//		private IpInterceptor ipInterceptor;


    	@Override
    	public void addInterceptors(InterceptorRegistry registry) {


			//设置响应header
			registry.addInterceptor(requestInterceptor);

//			//WEB IP拦截
//			InterceptorRegistration ipRegistration  = registry.addInterceptor(ipInterceptor);
//			ipRegistration.excludePathPatterns(ExcludePathConfig.getExApp());

    		// addPathPatterns 用于添加拦截规则
            // excludePathPatterns 配置某些路径不拦截
			//登录拦截
			InterceptorRegistration loginRegistration  = registry.addInterceptor(loginInterceptor);
			loginRegistration.excludePathPatterns(ExcludePathConfig.allEx);

			//线程信息增加
			InterceptorRegistration threadRegistration  = registry.addInterceptor(threadInterceptor);

			//权限拦截
			InterceptorRegistration securityRegistration  = registry.addInterceptor(securityInterceptor);
			securityRegistration.excludePathPatterns(ExcludePathConfig.allEx);
			securityRegistration.excludePathPatterns(ExcludePathConfig.getExApp());

			//敏感词拦截
			InterceptorRegistration wordRegistration  = registry.addInterceptor(wordsInterceptor);
			wordRegistration.excludePathPatterns(ExcludePathConfig.allEx);
    	}
    }

